package org.htmlparser.http;

import java.io.Serializable;
import java.util.Date;

public class Cookie
  implements Cloneable, Serializable
{
  private static final String SPECIALS = "()<>@,;:\\\"/[]?={} \t";
  protected String mComment;
  protected String mDomain;
  protected Date mExpiry;
  protected String mName;
  protected String mPath;
  protected boolean mSecure;
  protected String mValue;
  protected int mVersion;

  public Cookie(String paramString1, String paramString2)
    throws IllegalArgumentException
  {
    if ((!(isToken(paramString1))) || (paramString1.equalsIgnoreCase("Comment")) || (paramString1.equalsIgnoreCase("Discard")) || (paramString1.equalsIgnoreCase("Domain")) || (paramString1.equalsIgnoreCase("Expires")) || (paramString1.equalsIgnoreCase("Max-Age")) || (paramString1.equalsIgnoreCase("Path")) || (paramString1.equalsIgnoreCase("Secure")) || (paramString1.equalsIgnoreCase("Version")))
      throw new IllegalArgumentException("invalid cookie name: " + paramString1);
    this.mName = paramString1;
    this.mValue = paramString2;
    this.mComment = null;
    this.mDomain = null;
    this.mExpiry = null;
    this.mPath = "/";
    this.mSecure = false;
    this.mVersion = 0;
  }

  private boolean isToken(String paramString)
  {
    int i = 1;
    int j = paramString.length();
    for (int k = 0; (k < j) && (i != 0); ++k)
    {
      int l = paramString.charAt(k);
      if ((l < 32) || (l > 126) || ("()<>@,;:\\\"/[]?={} \t".indexOf(l) != -1))
        i = 0;
    }
    return i;
  }

  public Object clone()
  {
    Object localObject;
    try
    {
      localObject = super.clone();
      return localObject;
    }
    catch (CloneNotSupportedException localCloneNotSupportedException)
    {
      throw new RuntimeException(localCloneNotSupportedException.getMessage());
    }
  }

  public String getComment()
  {
    return this.mComment;
  }

  public String getDomain()
  {
    return this.mDomain;
  }

  public Date getExpiryDate()
  {
    return this.mExpiry;
  }

  public String getName()
  {
    return this.mName;
  }

  public String getPath()
  {
    return this.mPath;
  }

  public boolean getSecure()
  {
    return this.mSecure;
  }

  public String getValue()
  {
    return this.mValue;
  }

  public int getVersion()
  {
    return this.mVersion;
  }

  public void setComment(String paramString)
  {
    this.mComment = paramString;
  }

  public void setDomain(String paramString)
  {
    this.mDomain = paramString.toLowerCase();
  }

  public void setExpiryDate(Date paramDate)
  {
    this.mExpiry = paramDate;
  }

  public void setPath(String paramString)
  {
    this.mPath = paramString;
  }

  public void setSecure(boolean paramBoolean)
  {
    this.mSecure = paramBoolean;
  }

  public void setValue(String paramString)
  {
    this.mValue = paramString;
  }

  public void setVersion(int paramInt)
  {
    this.mVersion = paramInt;
  }

  public String toString()
  {
    String str;
    StringBuffer localStringBuffer = new StringBuffer(50);
    if (getSecure())
      localStringBuffer.append("secure ");
    if (getVersion() != 0)
    {
      localStringBuffer.append("version ");
      localStringBuffer.append(getVersion());
      localStringBuffer.append(" ");
    }
    localStringBuffer.append("cookie");
    if (getDomain() != null)
    {
      localStringBuffer.append(" for ");
      localStringBuffer.append(getDomain());
      if (getPath() != null)
        localStringBuffer.append(getPath());
      localStringBuffer.append(": ");
      localStringBuffer.append(getName());
      if (!(getName().equals("")))
        break label234;
      str = "";
      localStringBuffer.append(str);
      if (getValue().length() <= 40)
        break label241;
      localStringBuffer.append(getValue().substring(1, 40));
      localStringBuffer.append("...");
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          do
          {
            if (getComment() != null)
            {
              localStringBuffer.append(" // ");
              localStringBuffer.append(getComment());
            }
            return localStringBuffer.toString();
          }
          while (getPath() == null);
          localStringBuffer.append(" (path ");
          localStringBuffer.append(getPath());
          localStringBuffer.append(")");
        }
        label234: str = "=";
      }
      label241: localStringBuffer.append(getValue());
    }
  }
}